import Mock from 'mockjs'

const user_mobile='13201860552';
const user_token = user_mobile+'b358a8a296f8277ceb921cf';

const userInfo = Mock.mock({
  'data': 
    {
      id: '@id',//随机id
      name: '@name',//随机名称
      nickName: '@last',//随机昵称
      token:user_token,
      mobile: user_mobile,
      'age|11-99': 1,//年龄
      address: '@county(true)',//随机地址
      email: '@email',//随机邮箱
      isMale: '@boolean',//随机性别
      createTime: '@datetime',//创建时间
      avatar:"@image('80x80', '#FF6600', '头像')",
    }
})



export default [
  // user login
  {
    url: '/user/login',
    type: 'post',
    response: config => {
      const { mobile } = config.body
      if (mobile.length != 11) {
        return {
          code: 201,
          data:null,
          message: '手机号格式不正确.'
        }
      }

      if (mobile != user_mobile) {
        return {
          code: 201,
          data:null,
          message: '当前用户不存在，因为是模拟登陆，请登陆指定手机号：13201860552'
        }
      }

      return {
        code: 200,
        data: userInfo
      }
    }
  },

  // get user info
  {
    url: '/user/info',
    type: 'get',
    response: config => {
      const { token } = config.query;
      if (!token) {
        return {
          code: 403,
          message: 'token失效，请重新登录.'
        }
      }
      return {
        code: 200,
        data: userInfo
      }
    }
  },

  // user logout
  {
    url: '/user/logout',
    type: 'post',
    response: _ => {
      return {
        code: 200,
        data: 'success'
      }
    }
  }
]
